package com.study.fetch;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson2.JSON;
import com.study.fetch.HistPriceZsDTO.HistDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhuzi
 * 2024/4/5 15:25
 * 搜狐日K图
 */
@Slf4j
public class ShRkDemo {

    @Test
    public void rk() {
        String url = "https://hq.stock.sohu.com/mkline/cn/100/cn_{}-10_2.html?_={}";

        String body = HttpRequest.get(StrUtil.format(url, "512100", System.currentTimeMillis())).execute().body();
        String reqBody = StrUtil.subBetween(body, "quote_d_dividend(", ")");

        System.out.println(reqBody);

        HistPriceZsDTO histPriceZsDTO = JSON.parseObject(reqBody, HistPriceZsDTO.class);
        List<HistDetailDTO> histDetailDTOS = histPriceZsDTO.getDataDiv().stream().map(HistPriceZsDTO.HistDetailDTO::parse).collect(Collectors.toList());
        histDetailDTOS.forEach(item -> {
            System.out.println(item);
        });

    }
}
